package club.caihappy.config;

import club.caihappy.controller.MyFirstInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.*;

/**
 * Created by DELL on 2021/10/20
 **/
//SpringMVC只扫描Controller;子容器
//useDefaultFilters=false 禁用默认的过滤规则
@ComponentScan(value = "club.caihappy", includeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Controller.class)
}, useDefaultFilters = false)
@EnableWebMvc
public class AppConfig implements WebMvcConfigurer {

    //定制
    //视图解析器

    public void configureViewResolvers(ViewResolverRegistry registry) {
        //默认所有页面都从/WEB-INF/xxx.jsp
        //  registry.jsp();
        registry.jsp("/WEB-INF/views/", ".jsp");
    }

    //静态资源访问
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    //拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyFirstInterceptor()).addPathPatterns("/**");//任意多层路径，拦任意多的请求
    }
}
